package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemChoiceoppsiteBinding;
import com.sgb.kjwl.model.entity.business.StorageManEntity;
import com.sgb.kjwl.view.widget.OppositePersonPopWindow;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class OppositePersonAdpater<T> extends BaseRecycleAdapter<T> {


    public OppositePersonAdpater(Context context, List<T> datas) {
        super(context, R.layout.item_choiceoppsite, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, T t) {
        if(holder.getmBinding() instanceof ItemChoiceoppsiteBinding) {
            if (t instanceof OppositePersonPopWindow.ChoiceModel) {
                ((ItemChoiceoppsiteBinding) holder.getmBinding()).tvCategoryItem.setText(((OppositePersonPopWindow.ChoiceModel) t).getname());
                ((ItemChoiceoppsiteBinding) holder.getmBinding()).tvCategoryItem.setSelected(((OppositePersonPopWindow.ChoiceModel) t).isChoice());
                ((ItemChoiceoppsiteBinding) holder.getmBinding()).tvCategoryItem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        for (int i = 0; i < datas.size(); i++) {
                            ((OppositePersonPopWindow.ChoiceModel) datas.get(i)).setChoice(false);
                        }
                        if(onItemClick!=null){
                            onItemClick.onItemClick(t,holder.getIndex_position());
                        }
                        ((OppositePersonPopWindow.ChoiceModel) datas.get(holder.getIndex_position())).setChoice(true);
                        notifyDataSetChanged();
                    }
                });
            }

        }
    }
}
